package com.lxz.datasource.common;

import com.alibaba.fastjson.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * Controller基类，定义一些通用方法
 */
public abstract class BaseWebController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    protected HttpServletRequest request;
    @Autowired
    protected HttpServletResponse response;
    @Autowired
    protected HttpSession session;

    @ExceptionHandler(value = Exception.class)
    public ResultModel handlerOtherException(Exception e) {
        logger.error("handlerException", e);
        return ResultModel.error("系统异常");
    }


    @ExceptionHandler(value = JSONException.class)
    public ResultModel handlerJSONException(JSONException e) {
        logger.error("数据格式不正确", e);
        return ResultModel.error("数据格式不正确");
    }

}
